package com.example.demo;

import com.example.demo.entity.Person;
import com.example.demo.processor.MainConfig;
import com.example.demo.processor.MyBeanFactoryPostProcessor;
import com.example.demo.processor.MyBeanPostProcessor;
import com.example.demo.processor.MyInstantiationAwareBeanPostProcessor;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class Application {

    public static void main(String[] args) {


        System.out.println("现在开始初始化容器");

//        ApplicationContext factory = new ClassPathXmlApplicationContext("bean.xml");

        AnnotationConfigApplicationContext factory = new AnnotationConfigApplicationContext();
        factory.register(MyBeanFactoryPostProcessor.class, MyBeanPostProcessor.class, MyInstantiationAwareBeanPostProcessor.class);
        factory.register(MainConfig.class);
        factory.refresh();
        System.out.println("容器初始化成功");
        //得到Preson，并使用
        Person person = factory.getBean("person",Person.class);
        System.out.println(person);

        System.out.println("现在开始关闭容器！");
        ((AnnotationConfigApplicationContext)factory).registerShutdownHook();
        //SpringApplication.run(Application.class, args);
    }

}
